﻿<%@ Page Title="" Language="VB" MasterPageFile="~/Views/Shared/Base.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Permissions
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <ext:Viewport ID="ViewPort1" runat="server" Layout="fit">
        <Items>
            <ext:FormPanel ID="FormPanel1" runat="server" Padding="5" DefaultAnchor="0" Frame="false"
                BodyBorder="false" Shadow="None">
                <Items>
                    <ext:FieldSet ID="FieldSet1" runat="server" Title="审核" Collapsible="true" Layout="form">
                        <Items>
                            <ext:CheckboxGroup ID="cgCheck" runat="server" HideLabel="true">
                                <Items>
                                    <ext:Checkbox ID="chkP1" runat="server" BoxLabel="一审" Tag="1" />
                                    <ext:Checkbox ID="chkP2" runat="server" BoxLabel="二审" Tag="2" />
                                    <ext:Checkbox ID="chkP4" runat="server" BoxLabel="三审" Tag="4" />
                                    <ext:Checkbox ID="chkP8" runat="server" BoxLabel="审核会签" Tag="8" />
                                    <ext:Checkbox ID="chkP16" runat="server" BoxLabel="地价会签" Tag="16" />
                                    <ext:Checkbox ID="chkP32" runat="server" BoxLabel="审核报表" Tag="32" />
                                </Items>
                            </ext:CheckboxGroup>
                        </Items>
                    </ext:FieldSet>
                    <ext:FieldSet ID="FieldSet2" runat="server" Title="评估" Collapsible="true" Layout="form">
                        <Items>
                            <ext:CheckboxGroup ID="cgAssess" runat="server" HideLabel="true">
                                <Items>
                                    <ext:Checkbox ID="chkP64" runat="server" BoxLabel="评估工作报告" Tag="64" />
                                    <ext:Checkbox ID="chkP128" runat="server" BoxLabel="评估报表" Tag="128" />
                                </Items>
                            </ext:CheckboxGroup>
                        </Items>
                    </ext:FieldSet>
                    <ext:FieldSet ID="FieldSet3" runat="server" Title="总收发" Collapsible="true" Layout="form">
                        <Items>
                            <ext:CheckboxGroup ID="cgTransceiver" runat="server" HideLabel="true">
                                <Items>
                                    <ext:Checkbox ID="chkP256" runat="server" BoxLabel="总收发工作报告" Tag="256" />
                                    <ext:Checkbox ID="chkP512" runat="server" BoxLabel="总收发报表" Tag="512" />
                                </Items>
                            </ext:CheckboxGroup>
                        </Items>
                    </ext:FieldSet>
                    <ext:FieldSet ID="FieldSet4" runat="server" Title="系统" Collapsible="true" Layout="form">
                        <Items>
                            <ext:CheckboxGroup ID="cgSystem" runat="server" HideLabel="true">
                                <Items>
                                    <ext:Checkbox ID="chkP1024" runat="server" BoxLabel="系统设置" Tag="1024" />
                                </Items>
                            </ext:CheckboxGroup>
                        </Items>
                    </ext:FieldSet>
                </Items>
                <TopBar>
                    <ext:Toolbar ID="Toolbar1" runat="server">
                        <Items>
                            <ext:Button ID="btnSave" runat="server" Text="保存" Icon="Disk">
                                <Listeners>
                                    <Click Fn="doSave" />
                                </Listeners>
                            </ext:Button>
                        </Items>
                    </ext:Toolbar>
                </TopBar>
            </ext:FormPanel>
        </Items>
    </ext:Viewport>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeaderArea" runat="server">
    <script type="text/javascript" language="javascript">
        var _userid = '<%=ViewData("UserID") %>';
        var _totalpermission = Number('<%=ViewData("TotalPermission") %>');
        var _permissions = '<%=ViewData("Permissions") %>';

        var doSave = function (item, e) {
            var ctp = CalculateMask();

            if (ctp != _totalpermission) {
                $.ajax({
                    type: 'POST',
                    url: '<%= Url.Action("SavePermissions","Account") %>',
                    data: { userid: _userid, permissions: ctp },
                    success: function (data, textStatus) {
                        Ext.net.Notification.show({
                            iconCls: 'icon-information',
                            html: '保存记录成功',
                            title: '保存成功',
                            hideDelay: 5000
                        });
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        Ext.net.Notification.show({
                            iconCls: 'icon-exclamation',
                            html: textStatus,
                            title: '出错啦',
                            hideDelay: 5000
                        });
                    }
                });
            } else {
                Ext.net.Notification.show({
                    iconCls: 'icon-information',
                    html: '保存记录成功',
                    title: '保存成功',
                    hideDelay: 5000
                });
            }
        }

        function CalculateMask() {
            //cgCheck cgAssess cgTransceiver cgSystem
            var ctp = 0;
            for (i = 0; i < cgCheck.items.items.length; i++) {
                var c = cgCheck.items.items[i];
                if (c.checked) {
                    ctp += Number(c.tag);
                }
            }
            for (i = 0; i < cgAssess.items.items.length; i++) {
                var c = cgAssess.items.items[i];
                if (c.checked) {
                    ctp += Number(c.tag);
                }
            }
            for (i = 0; i < cgTransceiver.items.items.length; i++) {
                var c = cgTransceiver.items.items[i];
                if (c.checked) {
                    ctp += Number(c.tag);
                }
            }
            for (i = 0; i < cgSystem.items.items.length; i++) {
                var c = cgSystem.items.items[i];
                if (c.checked) {
                    ctp += Number(c.tag);
                }
            }
            return ctp;
        }

        Ext.onReady(function () {
            var permissions = _permissions.split(',');
            for (i = 0; i < permissions.length; i++) {
                eval('chkP' + permissions[i]).setValue(true);
            }
        });
    </script>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="StartupArea" runat="server">
</asp:Content>
